package se.lnu.axez.animation;

import se.lnu.axez.IControl;

public final class RotateControlAnimation extends Animation<IControl> {
	private static final float DEFAULT_FACTOR = 1f;
	
	private float fromAngle;
	private float toAngle;
	private float xFactor;
	private float yFactor;
	private float zFactor;

	public RotateControlAnimation() {
	}
	
	public RotateControlAnimation(float fromAngle, float toAngle) {
		this(fromAngle, toAngle, DEFAULT_FACTOR, DEFAULT_FACTOR, DEFAULT_FACTOR);
	}

	public RotateControlAnimation(float fromAngle, float toAngle, float xFactor, float yFactor, float zFactor) {
		this.setParams(fromAngle, toAngle, xFactor, yFactor, zFactor);
	}

	public void setParams(float fromAngle, float toAngle, float xFactor, float yFactor, float zFactor) {
		this.fromAngle = fromAngle;
		this.toAngle = toAngle;
		this.xFactor = xFactor;
		this.yFactor = yFactor;
		this.zFactor = zFactor;
	}

	@Override
	protected void applyTransformation(float interpolatedTime, IControl targetObject) {
        float degrees = this.fromAngle + ((this.toAngle - this.fromAngle) * interpolatedTime);
        targetObject.getTransformation().setRotation(degrees, this.xFactor, this.yFactor, this.zFactor);
	}
}
